//所在的省对应的list和id
var addressonelist = [];
var addressTowlist = [];
var addressThreelist = [];
var Alist = [];
var Blist = [];
var Clist = [];
var type = [];
//
var one = 0;
var tow = 0;
var three = 0;

var oneA = 0;
var towB = 0;
var threeC = 0;

var goods1 = 0;
var goods2 = 0;


//寄东西
getaddressone();
function getaddressone(){
    console.log('开始获取省级列表')
    $.ajax({
		url : ajax_host +'getaddressone.act',
		dataType:'JSON',
		
		success:function(resp){
			if(resp.success){
                addressonelist = resp.list;
                
				console.log("列表："+addressonelist);
				  renderAddressOne(addressonelist)
			}
		}
	})
}
function renderAddressOne(arr){
    var str = '<option value="0">请选择</option>';
    for(var i = 0; i<arr.length;i++){
		str+=`<option  value="${arr[i].nId}">${arr[i].nName}</option>`;
	}
	html('addressOne',str);
}
function change(){
    one = val('addressOne');
    console.log('one'+one);
    $.ajax({
		url : ajax_host +'getaddressTow.act',
		dataType:'JSON',
		data:{
			fid : one
		},
		success:function(resp){		
			if(resp.success){
            addressTowlist = resp.list;
			renderAddressTow(addressTowlist);
		}else{
			layer.alert(resp.errmsg);
		}
		}
	})
}
function renderAddressTow(arr){
	var str = '<option value="0">请选择</option>';
	for(var i = 0; i<arr.length;i++){
		str+=`<option  value="${arr[i].nId}">${arr[i].nName}</option>`;
	}
	html('addressTwo',str);
}
function change2(){
     tow = val('addressTwo');
    console.log('tow'+tow);
    $.ajax({
		url : ajax_host +'getaddressThree.act',
		dataType:'JSON',
		data:{
			fid : tow
		},
		success:function(resp){		
			if(resp.success){
             addressThreelist = resp.list;
			renderAddressThree(addressThreelist);
		}else{
			layer.alert(resp.errmsg);
		}
		}
	})
}
function renderAddressThree(arr){
	var str = '<option value="0">请选择</option>';
	for(var i = 0; i<arr.length;i++){
		str+=`<option  value="${arr[i].nId}">${arr[i].nName}</option>`;
	}
	html('addressThree',str);
}


function change3(){
     three = val('addressThree');
    console.log('three'+three);
    
}




//收东西
getaddressA();
function getaddressA(){
    console.log('开始获取省级列表')
    $.ajax({
		url : ajax_host +'getaddressone.act',
		dataType:'JSON',
		
		success:function(resp){
			if(resp.success){
                Alist = resp.list;
				console.log("列表："+Alist);
				  renderAddressA(Alist)
			}
		}
	})
}
function renderAddressA(arr){
    var str = '<option value="0">请选择</option>';
    for(var i = 0; i<arr.length;i++){
		str+=`<option  value="${arr[i].nId}">${arr[i].nName}</option>`;
	}
	html('addressA',str);
}
function change4(){
    oneA = val('addressA');
    console.log('oneA'+oneA);
    $.ajax({
		url : ajax_host +'getaddressTow.act',
		dataType:'JSON',
		data:{
			fid : oneA
		},
		success:function(resp){		
			if(resp.success){
                Blist = resp.list;
			renderAddressB(Blist);
		}else{
			layer.alert(resp.errmsg);
		}
		}
	})
}
function renderAddressB(arr){
    var str = '<option value="0">请选择</option>';
    for(var i = 0; i<arr.length;i++){
		str+=`<option  value="${arr[i].nId}">${arr[i].nName}</option>`;
	}
	html('addressB',str);
}
function change5(){
    towB = val('addressB');
   console.log('towB'+towB);
   $.ajax({
       url : ajax_host +'getaddressThree.act',
       dataType:'JSON',
       data:{
           fid : towB
       },
       success:function(resp){		
           if(resp.success){
            Clist = resp.list;
           renderAddressC(Clist);
       }else{
		layer.alert(resp.errmsg);
       }
       }
   })
}
function renderAddressC(arr){
    var str = '<option value="0">请选择</option>';
    for(var i = 0; i<arr.length;i++){
		str+=`<option  value="${arr[i].nId}">${arr[i].nName}</option>`;
	}
	html('addressC',str);
}
function change6(){
    threeC = val('addressC');
   console.log('threeC'+threeC);
   
}


//获得物品类型
getType();
function getType(){
    console.log('获得物品类型')
    $.ajax({
		url : ajax_host +'getType.act',
		dataType:'JSON',
		
		success:function(resp){
			if(resp.success){
                type = resp.list;
				console.log("列表："+type);
				  renderType(type)
			}
		}
	})
}
function renderType(arr){
    var str = '<option value="-1">请选择</option>';
    for(var i = 0; i<arr.length;i++){
		str+=`<option  value="${arr[i].tId}">${arr[i].tName}</option>`;
	}
	html('goods1',str);
}
function change7(){
   goods1 = val('goods1');
   console.log('goods1'+goods1);
   $.ajax({
       url : ajax_host +'getType2.act',
       dataType:'JSON',
       data:{
           fid : goods1
       },
       success:function(resp){		
           if(resp.success){
            var typelist = resp.list;
            console.log(typelist);
            renderType2(typelist);
       }else{
		layer.alert(resp.errmsg);
       }
       }
   })
}
function renderType2(arr){
    var str = '<option value="-1">请选择</option>';
    for(var i = 0; i<arr.length;i++){
		str+=`<option  value="${arr[i].tId}">${arr[i].tName}</option>`;
	}
	html('goods2',str);
}
function change8(){
   goods2 = val('goods2');
   console.log('goods2'+goods2);
   
}


//提交
function doSubmit(){
    console.log('1---:'+one);
    console.log('2---:'+tow);
    console.log('3---:'+three);
    var Address = val('Address');
    console.log('4---:'+Address);
    var eName = val('eName');
    console.log('5---:'+eName);

    console.log('a---:'+oneA);
    console.log('b---:'+towB);
    console.log('c---:'+threeC);
    var Address2 = val('Address2');
    console.log('d---:'+Address2);
    var shouName = val('shouName');
    var shouTell = val('shouTell');
    
    console.log('e---:'+shouName);
    console.log('f---:'+shouTell);

    $.ajax({
		url:ajax_host+'updateAddress.act',
		type : 'post',
		dataType:'JSON',
		data:{
            one:one,
            tow:tow,
            three:three,
            Address:Address,
            oneA:oneA,
            towB:towB,
            threeC:threeC,
            Address2:Address2,
            shouName:shouName,
            shouTell:shouTell,
            goods1:goods1,
            goods2:goods2,
            eName:eName
		},
		success:function(resp){
			
			if(resp.success){
				//关闭遮罩
				$('#doUpdate').modal('hide', 'fit');
				layer.alert('提交成功');
			}else{
				$('#doUpdate').modal('hide', 'fit');
				layer.alert(resp.errmsg);
			}
		}
})

}

